﻿@namespace Masa.Blazor.Presets
@typeparam TItem
@typeparam TItemValue

<MBottomSheet ContentClass="p-mobile-cascader__content"
              Value="Visible"
              ValueChanged="HandleVisibleChanged">
    <ActivatorContent>
        @ActivatorContent?.Invoke(context)
    </ActivatorContent>
    <ChildContent>
        <MSheet Class="p-mobile-cascader__header">
            <MButton Plain Color="primary" OnClick="OnCancel">@I18n.T("$masaBlazor.cancel")</MButton>
            <div class="p-mobile-cascader__title">@Title</div>
            <MButton Plain Color="primary" OnClick="HandleOnConfirm">@I18n.T("$masaBlazor.ok")</MButton>
        </MSheet>

        <MTabs Value="@_tabIndex" 
               ValueChanged="val => _tabIndex = val.AsT1"
               @ref="_tabs">
            @foreach (var tab in Tabs)
            {
                <MTab>@tab</MTab>
            }
        </MTabs>

        <MList Dense Height="@Height" Class="p-mobile-cascader__list">
            @if (IsLoading)
            {
                <MSkeletonLoader Type="list-item-three-line"></MSkeletonLoader>
            }
            else
            {
                foreach (var item in CurrentItems)
                {
                    <MListItem OnClick="() => OnItemClick(item)"
                               Disabled="@IsDisabled(item)">
                        <MListItemContent>
                            <MListItemTitle>@ItemText(item)</MListItemTitle>
                        </MListItemContent>
                        <MListItemIcon Class="align-center">
                            @if (SelectedItems.Contains(item))
                            {
                                <MIcon Color="primary" Dense>$complete</MIcon>
                            }
                        </MListItemIcon>
                    </MListItem>
                }
            }
        </MList>
    </ChildContent>
</MBottomSheet>
